﻿/// Write a program, that reads from the console an array of N integers and an integer K, 
/// sorts the array and using the method Array.BinSearch() finds the largest number in the array which is ≤ K. 



using System;

class zad4
{

    static void Main()
    {
        int[] arr = { 1, 2, 6, 3, 4 };
        int k = 5;

        Array.Sort(arr);

        int index = Array.BinarySearch(arr, k);
        
        if (k < arr[0])
        {
            Console.WriteLine("No element <= {0} in the array", k);
        }
        else if (index < 0)
        {
            Console.WriteLine(arr[~index - 1]);
        }
        else
        {
            Console.WriteLine(arr[index]);
        }
    }
}

